fix(auth): recover OIDC login when callback arrives in a different br… - #205
Open
GabrielMSilva04 wants to merge 1 commit into
Open
fix(auth): recover OIDC login when callback arrives in a different br…#205GabrielMSilva04 wants to merge 1 commit into
GabrielMSilva04 wants to merge 1 commit into
Conversation
…owser
When a user clicks an Authentik verification email in Gmail/iOS Mail the
callback opens in a new browser context with no oauth_state cookie, causing
a 401 "session expired" — even though the verification succeeded.
Three fixes applied together:
Fix 1: Server-side PKCE state storage
- New OAuthState table stores state/verifier/nonce/redirect per-request
- oidc_login persists state to DB alongside the cookie
- oidc_callback uses the cookie (fast path) and falls back to the DB row
when the cookie is absent; DB failure is non-fatal (cookie still works)
- cleanup_expired_oauth_states() runs at startup to prune stale rows
- Alembic migration: b9e4c7f2a1d8
Fix 2: Distinct error code for the cross-browser case
- _verify_and_pop_state_cookie raises detail="missing_state_cookie"
only when both cookie and DB fallback fail
- oidc_callback maps that detail to error=email_verified_relogin instead
of the generic error=session
- Login page renders email_verified_relogin as a green success notice
("Your account is verified! Sign in to continue.") with a "Sign in"
button, since the email verification itself succeeded
Fix 3: Extend state cookie TTL from 10 min to 30 min
- Covers slow email delivery without meaningful security impact
- Same constant used for both the cookie max_age and DB expires_at
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


…owser
When a user clicks an Authentik verification email in Gmail/iOS Mail the callback opens in a new browser context with no oauth_state cookie, causing a 401 "session expired" — even though the verification succeeded.
Three fixes applied together:
Fix 1: Server-side PKCE state storage
Fix 2: Distinct error code for the cross-browser case
Fix 3: Extend state cookie TTL from 10 min to 30 min